package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Username string `gorm:"type:varchar(20);not null;unique;"`
	Password string `gorm:"type:varchar(32);not null;"`
}

type UserRealname struct {
	gorm.Model
	UserId   int64  `gorm:"type:int;"`
	Realname string `gorm:"type:varchar(20);"`
	IdCard   string `gorm:"type:varchar(20);"`
}

func (u *User) Create() error {
	return DB.Debug().Create(&u).Error
}

func (u *User) FindUser(username string) error {
	return DB.Debug().Where("username=?", username).Find(&u).Error
}
func (ur *UserRealname) Create() error {
	return DB.Debug().Create(&ur).Error
}
func (ur *UserRealname) CheckRealname(userid int64, idCard string) error {
	return DB.Debug().Where("user_id=? and realname=?", userid, idCard).Find(&ur).Error
}
